/**
 * 
 */
package com.sci.web.action.datareportseason.strategy;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import com.sci.web.action.util.BaseAction;
import com.sci.web.bean.Enterprise_Brand;
import com.sci.web.bean.Enterprise_Management;
import com.sci.web.bean.Enterprise_Strategy;
import com.sci.web.dao.DataReportM_InnovateBaseDao;

/**
 * @author  BaiFuyou
 * @date: Nov 10, 2011 5:46:50 PM
 */
public class Addnewstrategy_management_brand_Action extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5705265608462185033L;
	@Resource
	private DataReportM_InnovateBaseDao dataReportM_InnovateBaseDao;
	private int type;
	private int flag;
	private String year;
	private String frist;
	private String second;
	private int userId;
	/**
	 * @return the type
	 */
	public int getType() {
		return type;
	}
	/**
	 * @param type the type to set
	 */
	public void setType(int type) {
		this.type = type;
	}
	/**
	 * @return the flag
	 */
	public int getFlag() {
		return flag;
	}
	/**
	 * @param flag the flag to set
	 */
	public void setFlag(int flag) {
		this.flag = flag;
	}
	/**
	 * @return the year
	 */
	public String getYear() {
		return year;
	}
	/**
	 * @param year the year to set
	 */
	public void setYear(String year) {
		this.year = year;
	}
	/**
	 * @return the frist
	 */
	public String getFrist() {
		return frist;
	}
	/**
	 * @param frist the frist to set
	 */
	public void setFrist(String frist) {
		this.frist = frist;
	}
	/**
	 * @return the second
	 */
	public String getSecond() {
		return second;
	}
	/**
	 * @param second the second to set
	 */
	public void setSecond(String second) {
		this.second = second;
	}
	/**
	 * @return the userId
	 */
	public int getUserId() {
		return userId;
	}
	/**
	 * @param userId the userId to set
	 */
	public void setUserId(int userId) {
		this.userId = userId;
	}
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		super.setContentType(super.JSON);
		Map<String, Object> map = new HashMap<String, Object>();
		if(flag == 1){
			map.put("strategy_year", year);
			map.put("strategy_type", type);
			map.put("uid", userId);
			if(dataReportM_InnovateBaseDao.isEnterprise_StrategyExistBeforeInsert(map)){
				super.outPrint("already");
				return "json";
			}
			map.clear();
			Enterprise_Strategy es = new Enterprise_Strategy();
			es.setEditable(1);es.setEnterprise_id(dataReportM_InnovateBaseDao.getEnterpriseBaseId(userId));
			es.setStrategy_check_pass(3);
			es.setStrategy_id(0);es.setStrategy_implement(second);es.setStrategy_is_new(0);es.setStrategy_made(frist);
			es.setStrategy_type(type);es.setStrategy_year(year);
			if(dataReportM_InnovateBaseDao.insertNewEnterprise_StrategyData(es)){
				super.outPrint("ok");
				return "json";
			}else{
				super.outPrint("fail");
				return "json";
			}
		}
		if(flag == 2){
			map.put("management_year", year);
			map.put("management_type", type);
			map.put("uid", userId);
			if(dataReportM_InnovateBaseDao.isExistBeforeInsertEnterprise_Management(map)){
				super.outPrint("already");
				return "json";
			}
			map.clear();
			Enterprise_Management em = new Enterprise_Management();
			em.setEditable(1);em.setEnterprise_id(dataReportM_InnovateBaseDao.getEnterpriseBaseId(userId));
			em.setManagement_check_pass(3);em.setManagement_encourage(frist);em.setManagement_id(0);em.setManagement_intellectual_property(second);
			em.setManagement_is_new(0);em.setManagement_type(type);em.setManagement_year(year);
			if(dataReportM_InnovateBaseDao.insertNewEnterprise_ManagementData(em)){
				super.outPrint("ok");
				return "json";
			}else{
				super.outPrint("fail");
				return "json";
			}
			
		}
		if(flag == 3){
			map.put("brand_year", year);
			map.put("brand_type", type);
			map.put("uid", userId);
			if(dataReportM_InnovateBaseDao.isExistBeforeInsertEnterprise_Brand(map)){
				super.outPrint("already");
				return "json";
			}
			Enterprise_Brand eb = new Enterprise_Brand();
			eb.setBrand_check_pass(3);
			eb.setBrand_have(frist);
			eb.setBrand_id(0);
			eb.setBrand_is_new(0);
			eb.setBrand_make(second);
			eb.setBrand_type(type);
			eb.setBrand_year(year);
			eb.setEditable(1);
			eb.setEnterprise_id(dataReportM_InnovateBaseDao.getEnterpriseBaseId(userId));
			if(dataReportM_InnovateBaseDao.insertNewEnterprise_BrandData(eb)){
				super.outPrint("ok");
				return "json";
			}else{
				super.outPrint("fail");
				return "json";
			}
		}
		return "json";
	}

}
